<template>
    <div>
        <div class="layout-main">
            <el-form ref="sysAddress" label-position="right" label-width="80px" :model="sysAddress" :rules="rules">
                <input type="hidden" :model="sysAddress.id" />
                <el-form-item label="发件人" prop="linkName">
                    <el-input size="small" v-model="sysAddress.linkName" placeholder="发件人" style="width: 240px" />
                </el-form-item>
                <el-form-item label="手机号码" prop="phone">
                    <el-input size="small" v-model="sysAddress.phone" placeholder="手机号码" style="width: 240px" />
                </el-form-item>
                <el-form-item label="发货地址" prop="address">
                    <el-input size="small" v-model="sysAddress.address" placeholder="发货地址" style="width: 240px" />
                </el-form-item>
            </el-form>
            <div>
                <el-button size="small" @click="cancel">取消</el-button>
                <el-button size="small" type="primary" :loading="modalLoading" @click="ok">确定</el-button>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    name: 'SysAddress',
    data() {
        return {
            loading: false,
            modalLoading: false,

            
            sysAddress: {

            },
            rules: {
                address: [{ required: true, message: "地址必填" }],
                linkName: [{ required: true, message: "发件人必填" }],
                phone: [{ required: true, message: "电话必填" }]
            },

        };
    },
    mounted: function() {

        this.getDetail();

    },
    methods: {

        getDetail: function() {

            var me = this;
            me.showLoading();
            me.$http.post("/sys/sysaddress/getpm.action").then(response => {
                var body = response;
                if (body.status == 0) {
                    me.sysAddress = body.obj;

                }
                else{
                    me.errorMessage(body.info);
                }
                me.hideLoading();
            }, response => {
                me.hideLoading();
            });
        },

        ok: function() {
            var ok = false;
            this.$refs['sysAddress'].validate((valid) => {
                ok = valid;
                if (valid) {

                } else {
                    this.errorMessage('请认真填写数据');
                }
            })
            if (!ok) return;
            var me = this;

            me.modalLoading = true;
            me.$http.post("/sys/sysaddress/doSave.action", me.sysAddress).then(response => {
                var body = response;
                if (body.status == 0) {
                    me.successMessage("保存成功！");

                    me.modalEdit = false;

                } else {
                    me.errorMessage( body.info);
                }
                me.modalLoading = false;
            }, response => {
                me.modalLoading = false;
            });
        },
        cancel: function() {
            this.getDetail();
        }
    }
}
</script>
<style scoped>
</style>